import 'dart:async';
import 'package:flame/components.dart';
import 'package:flame/flame.dart';
import 'package:flutter/cupertino.dart';
import 'common_util.dart';

class CardImage extends PositionComponent {
  CardImage(
      {required Vector2 cardSize,
      required Vector2 position,
      double this.cardImageRotation = 0,
      required int this.cardCode})
      : super(size: cardSize, position: position);
  int cardCode;
  double cardImageRotation;

  @override
  FutureOr<void> onLoad() {
    debugMode = true;
    return super.onLoad();
  }

  @override
  @mustCallSuper
  void render(Canvas canvas) {
    var cardImage = Flame.images.fromCache(CommonUtil.getCardImage(cardCode));
    Rect rect = Rect.fromLTWH(position.x, position.y, size.x, size.y);
    Sprite(cardImage).renderRect(canvas, rect);
    super.render(canvas);
  }
}
